
package com.cpj.signin.controller;

import com.cpj.signin.entity.Message;
import com.cpj.signin.service.SignInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/signin")
public class SignInController {

    @Autowired
    private SignInService signInService;

    /**
     * 用户签到
     * @param userName 用户名
     * @return 签到结果
     */
    @PostMapping("/{userName}")
    public Map<String, Object> signIn(@PathVariable String userName) {
        return signInService.signIn(userName);
    }

    /**
     * 获取用户当月签到情况
     * @param userName 用户名
     * @return 当月签到情况
     */
    @GetMapping("/{userName}/status")
    public Map<String, Object> getMonthlySignInStatus(@PathVariable String userName) {
        return signInService.getMonthlySignInStatus(userName);
    }

    /**
     * 添加留言
     * @param userName 用户名
     * @param requestBody 请求体，包含留言内容
     * @return 添加的留言
     */
    @PostMapping("/{userName}/message")
    public Message addMessage(@PathVariable String userName, @RequestBody Map<String, String> requestBody) {
        String content = requestBody.get("content");
        return signInService.addMessage(userName, content);
    }

    /**
     * 获取用户的所有留言
     * @param userName 用户名
     * @return 留言列表
     */
    @GetMapping("/{userName}/messages")
    public List<Message> getUserMessages(@PathVariable String userName) {
        return signInService.getUserMessages(userName);
    }
}
